package smdc.order.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import smdc.common.annotation.Log;
import smdc.common.core.controller.BaseController;
import smdc.common.core.domain.AjaxResult;
import smdc.common.enums.BusinessType;
import smdc.order.domain.MenuCategory;
import smdc.order.service.IMenuCategoryService;
import smdc.common.utils.poi.ExcelUtil;
import smdc.common.core.page.TableDataInfo;

/**
 * 菜单分类Controller
 * 
 * @author 毛锐
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/order/category")
public class MenuCategoryController extends BaseController
{
    @Autowired
    private IMenuCategoryService menuCategoryService;

    /**
     * 查询菜单分类列表
     */
    @PreAuthorize("@ss.hasPermi('order:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(MenuCategory menuCategory)
    {
        startPage();
        List<MenuCategory> list = menuCategoryService.selectMenuCategoryList(menuCategory);
        return getDataTable(list);
    }

    /**
     * 导出菜单分类列表
     */
    @PreAuthorize("@ss.hasPermi('order:category:export')")
    @Log(title = "菜单分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuCategory menuCategory)
    {
        List<MenuCategory> list = menuCategoryService.selectMenuCategoryList(menuCategory);
        ExcelUtil<MenuCategory> util = new ExcelUtil<MenuCategory>(MenuCategory.class);
        util.exportExcel(response, list, "菜单分类数据");
    }

    /**
     * 获取菜单分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:category:query')")
    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable("categoryId") Long categoryId)
    {
        return success(menuCategoryService.selectMenuCategoryByCategoryId(categoryId));
    }

    /**
     * 新增菜单分类
     */
    @PreAuthorize("@ss.hasPermi('order:category:add')")
    @Log(title = "菜单分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuCategory menuCategory)
    {
        return toAjax(menuCategoryService.insertMenuCategory(menuCategory));
    }

    /**
     * 修改菜单分类
     */
    @PreAuthorize("@ss.hasPermi('order:category:edit')")
    @Log(title = "菜单分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuCategory menuCategory)
    {
        return toAjax(menuCategoryService.updateMenuCategory(menuCategory));
    }

    /**
     * 删除菜单分类
     */
    @PreAuthorize("@ss.hasPermi('order:category:remove')")
    @Log(title = "菜单分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds)
    {
        return toAjax(menuCategoryService.deleteMenuCategoryByCategoryIds(categoryIds));
    }
}
